package com.guw.AWT;

import java.awt.*;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;

public class TestPaint {
    public static void main(String[] args) {
        new MyPaint().loadFrame();
    }
}

class MyPaint extends Frame{

    public void loadFrame(){
        setBounds(200,200,600,500);
        setVisible(true);
        windowClose(this);
    }


    @Override
    public void paint(Graphics g) {
        //画笔,需要有颜色
        g.setColor(Color.red);
        g.drawOval(100,100,100,100);
        g.fillOval(200,200,100,100);

        g.setColor(Color.blue);
        g.fillRect(150,200,200,200);
    }

    //重写一个关闭的方法
    private static void windowClose(Frame frame){
        frame.addWindowListener(new WindowAdapter() {
            @Override
            public void windowClosing(WindowEvent e) {
                System.exit(0);
            }
        });

    }
}